<template>
  <UploadExcel :on-success="handleSuccess"></UploadExcel>
</template>

<script>
import { transExcel } from "@/utils/index";
import { importEmployees } from "@/api/employees";

export default {
  methods: {
    handleSuccess({ header, results }) {
      // header 标题
      //        ['姓名','手机号']
      // results excel表格的内容
      //        [ {'姓名'：'小张'， '手机号': '13712345678'}, {.....} ]
      console.log(header, results);
      const data = transExcel(results);
      console.log(data);
      this.doImport(data);
    },
    async doImport() {
      try {
        const res = await importEmployees(data);
        console.log(res);
        this.$message.success(res.message);
        this.$router.push("/employees");
      } catch (err) {
        this.$message.error(err.message);
      }
    },
  },
};
</script>

<style>
</style>